package com.imooc.project.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录拦截器
public class LoginInterceptor implements HandlerInterceptor {

    @Override
//    请求前执行
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (request.getSession().getAttribute("account") == null){
            response.sendRedirect("/auth/error");
            System.out.println("------------------------拦截成功-----------------------------");
            return false;
        }
        System.out.println("===================放行通过===================");
        return true;
    }
}
